//对axios进行二次封装，添加请求头等内容
import axios from "axios";
import qs from 'qs'
import { Indicator } from 'mint-ui';
import state from "../vuex/state";
const instance = axios.create({
baseURL:'/api',
timeout:20000
})
//请求拦截器
instance.interceptors.request.use((config)=>{
    const data = config.data
    if(data instanceof Object){
        //将对象变为查询字符串参数
            config.data=qs.stringify(data)
    }
    config.headers.authorization=state.user.token
    Indicator.open();
    return config
})

//响应拦截器
instance.interceptors.response.use((res)=>{
        Indicator.close();
return res.data
},(err)=>{
    Indicator.close();
    //返回pending状态Promise,中断promise链
    return new Promise(()=>{})
})
export default instance

